<%@ page import="schoolsource.sql.SchoolDBSQL" %>
<%@ page import="java.text.*" %>
<%@ page import="schoolsource.model.*" %>
<%@ page import="schoolsource.gui.FormFields" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<% SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION);
   String requestObject = (String) st.getValue(FormFields.TOKEN);
   int classnum = (new Integer((String) st.getValue(FormFields.CLASSNUM))).intValue();
   ClassContainer classC[] = (ClassContainer[]) st.getValue("classContainer");
   UserContainer studentC[] = (UserContainer[]) st.getValue("studentsInClass");
   GradeContainer gradeC[] = (GradeContainer[]) st.getValue("grades");
   int hwnum = (new Integer((String) st.getValue(FormFields.HWNUM))).intValue();
   HomeworkContainer homeworkC[] = (HomeworkContainer[]) st.getValue("homeworkContainer");
   SubmissionContainer submissionC[] = (SubmissionContainer[]) st.getValue("submissions");
   String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
   String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
%>
   


<HTML>
  <HEAD>
      <SCRIPT LANGUAGE="JavaScript">
      
        function validate(x) {
            if ("" != x.value) {
                var db = /(^\d*\.?\d*$)/;
                var result = x.value.match(db);
                if (null == result) {
                    alert ("Grades must be numeric");
            var thename = x.name;
            x.value = "";
            x.focus();
                }
            }
        }
      
      </SCRIPT>
  </HEAD>
  <BODY >
      <FORM NAME="classhomeworkgrades" METHOD="POST">
    <TABLE ALIGN="LEFT" BORDER="0" STYLE="font-family:sans-serif;font-size:11;">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= requestObject%>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CLASSNUM %>" VALUE="<%= classnum %>">
        <INPUT TYPE="HIDDEN" NAME="<%= SchoolDBSQL.HWASSIGNEDID %>" VALUE="<%= ((hwnum == -1) ? "-1" : homeworkC[hwnum].getHomeworkID().toString()) %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.USRTYPE %>" VALUE="<%= loginType %>">
      
      <TR STYLE="font-family:sans-serif;font-size:13;font-weight:bold;">
        <TD COLSPAN=2><%= homeworkC[hwnum].getShortName().toString() %>
        </TD>
      </TR>
      <TR STYLE="font-family:sans-serif;font-size:12;font-weight:bold;">
        <TD COLSPAN=2>Total Points Possible: <%= homeworkC[hwnum].getTotalPoints().toString() %>
        </TD>
      </TR>
      <TR>
        <TD>
          <CENTER><INPUT TYPE="SUBMIT" NAME="<%= FormFields.BUTTONCLICKED %>" VALUE="Save Grade"></CENTER>
        </TD>
        <TD>
          <CENTER><INPUT TYPE="SUBMIT" NAME="<%= FormFields.BUTTONCLICKED %>" VALUE="Cancel"></CENTER>
        </TD>
      </TR>
      &nbsp;<br>
      <TR STYLE="font-family:sans-serif;font-size:12;font-weight:bold;">
        <TD>Student</TD>
        <TD>Points</TD>
        <TD>Comment</TD>
        <TD STYLE="width=120;"><CENTER>Allow<BR>Submission</CENTER></TD>
        <TD STYLE="width=100;"><CENTER>View<BR>Submission</CENTER></TD>
      </TR>
        <%
        DecimalFormat formatter = new DecimalFormat();
        formatter.setDecimalSeparatorAlwaysShown(false);
        if (studentC != null) {
            for (int i = 0; i < studentC.length; i++) {
                out.println("<TR STYLE=\"font-size:11;\";>");
                out.println("<TD>" + studentC[i].getLastName() + ", " + studentC[i].getFirstName() + ": </TD>");
                out.println("<TD><INPUT STYLE=\"font-size:11;\"; TYPE=\"TEXT\" SIZE=\"8\"  onBlur=\"validate(this);\" NAME=\"" + SchoolDBSQL.GRADESCORE + studentC[i].getAssignedID().toString() + "\" VALUE=\"" + ("-1.0".equals(gradeC[i].getGrade().toString()) ? "" : formatter.format(((Double) gradeC[i].getGrade().getObject()).doubleValue())) + "\"></TD>");
                out.println("<TD><INPUT STYLE=\"font-size:11;\"; TYPE=\"TEXT\" SIZE=\"50\" NAME=\"" + SchoolDBSQL.GRADECOMMENT + studentC[i].getAssignedID().toString() + "\" VALUE=\"" + gradeC[i].getComment().toString() + "\"></TD>");
                out.println("<TD ALIGN=\"CENTER\";STYLE=\"width=120;\";><INPUT TYPE=\"CHECKBOX\" NAME=\"" + SchoolDBSQL.SUBMISSIONUPDATEALLOWED + studentC[i].getAssignedID().toString() + "\" VALUE=\"TRUE\"" + submissionC[i].getUpdateAllowed().getCheckedString() + "></TD>");
                // get the file from the submissions container 
                if(submissionC[i] != null && !"".equals(submissionC[i].getFilePath().toString())) {
                    out.println("<TD ALIGN=\"CENTER\";STYLE=\"width=100;\";><a href=\"..\\" + submissionC[i].getFilePath().toString()+ submissionC[i].getFileName().toString() + "\" target='4087996' onClick=\"window.open('','4087996','width=640,height=480,resizeable=1,status=1,scrollbars=1,menubar=1');\"><IMG src=\"..\\text.gif\" border=0 width=18></TD>");
                }
                out.println("</TR>");
            } 
        }
        %>
    &nbsp;<br>
      <TR>
        <TD>
          <LEFT><INPUT TYPE="SUBMIT" NAME="<%= FormFields.BUTTONCLICKED %>" VALUE="Save Grade">
        </TD>
        <TD>
          <INPUT TYPE="SUBMIT" NAME="<%= FormFields.BUTTONCLICKED %>" VALUE="Cancel"></LEFT>
        </TD>
      </TR>
      </TABLE>
      </FORM>
  </BODY>
</HTML>
